package com.abkj.platform.tail.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.abkj.platform.base.dao.warp.MapperWrap;
import com.abkj.platform.base.dao.warp.SQLType;
import com.abkj.platform.tail.service.IAlertService;

@Service("AlertService")
public class AlertService extends BaseServiceImpl
  implements IAlertService
{
	@Autowired
	private MapperWrap mapperWrap;
	
  @Override
	public Map<String, Object> getForm(){
		String sql = "SELECT * FROM alertSetting order by id desc";
		List list = this.mapperWrap.findBySql(sql);
		if (list.size() > 0) {
			return (Map<String, Object>)list.get(0);
		}else {
			return new HashMap<String, Object>();
		}
	}
  @Override
	public Boolean update(Map<String, Object> map){
		Boolean isSucess = true;
		StringBuffer sqlBuffer = new StringBuffer();
		Object ableObj = map.get("able");
		if (ableObj != null) {
			sqlBuffer.append("able=").append(ableObj.toString());
		}
		Object minuteObj = map.get("minute");
		if (minuteObj != null) {
			if (sqlBuffer.length() > 0) {
				sqlBuffer.append(",");
			}
			sqlBuffer.append("minute=").append(minuteObj.toString());
		}
		try {
			this.excuteBySql(SQLType.UPDATE, "update alertSetting set " + sqlBuffer.toString());
		} catch (Exception e) {
			isSucess = false;
		}
		return isSucess;
	}
}